package cn.dapeng.test;

import java.time.Duration;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

public class VirtualThread_T02 {

    public static void main(String[] args) throws Exception {
        Set<String> threadName = ConcurrentHashMap.newKeySet();

        ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();

        IntStream.range(0, 100000).forEach(i -> {
            executor.submit(() -> {
                Thread.sleep(Duration.ofSeconds(1));
                String threadInfo = Thread.currentThread().getName();
                threadName.add(threadInfo);
                return i;
            });
        });


        System.out.println("platform thread count: " + threadName.size());

        System.in.read();

    }
}
